 TaskManagement.vue
<template>
    <div>
      <!-- 搜索栏 -->
      <el-form :model="taskQuery" label-position="right" label-width="100px">
        <el-row :gutter="15">
          <el-col :span="6">
            <el-form-item  label="任务名称">
              <el-input v-model="taskQuery.taskName"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="任务类型">
              <el-select v-model="taskQuery.taskType" clearable placeholder="Select" style="width: 100%">
                <el-option v-for="item in taskTypeOption" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="任务状态">
              <el-select v-model="taskQuery.taskStatus" clearable placeholder="Select" style="width: 100%">
                <el-option v-for="item in taskStatusOption" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="15">
          <el-col :span="6">
            <el-form-item label="执行日期">
              <el-date-picker
                  v-model="taskQuery.executionDate"
                  type="date"
                  value-format="YYYY-MM-DD"
                  aria-label="Pick a date"
                  placeholder="Pick a date"
                  style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="执行时间">
              <el-time-picker
                  v-model="taskQuery.executionTime"
                  type="date"
                  value-format="HH:mm:ss"
                  aria-label="Pick a time"
                  placeholder="Pick a time"
                  style="width: 100%"
              />
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-form-item>
              <el-button type="primary" @click="onSubmit">搜索</el-button>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-form-item>
              <el-button type="info" @click="reset">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
  
      <!-- 列表展示 -->
      <el-table :data="taskList" stripe table-layout="fixed" >
        <el-table-column prop="id" label="ID"></el-table-column>
        <el-table-column prop="taskName" label="任务名称"></el-table-column>
        <el-table-column prop="taskContent" label="通知内容"></el-table-column>
        <el-table-column prop="taskStatus" label="激活状态">
          <template #default="scope">
            {{ getValueFromLabel(taskStatusOption,scope.row.taskStatus)}}
          </template>
        </el-table-column>
        <el-table-column prop="taskUsername" label="创建人"></el-table-column>
        <el-table-column prop="executionDate" label="执行日期"></el-table-column>
        <el-table-column prop="executionTime" label="执行时间"></el-table-column>
        <el-table-column prop="createTime" label="创建时间"></el-table-column>
        <el-table-column prop="updateTime" label="更新时间"></el-table-column>
        <el-table-column fixed="right" label="操作" min-width="120">
          <template #default="scope" >
            <el-button link type="primary" size="small" @click="edit">编辑</el-button>
            <el-button link type="primary" size="small" @click="bandTask">订阅</el-button>
            <el-button link type="primary" size="small" @click="queryBandUser">订阅用户</el-button>
<!--            删除二次提示-->
            <el-popconfirm
                confirm-button-text="是"
                cancel-button-text="否"
                hide-icon:true
                title="确认删除此任务?"
                @confirm=deleteMyTask(scope.row)
            >
              <template #reference>
                <el-button link type="danger" size="small">删除</el-button>
              </template>
            </el-popconfirm>

          </template>
        </el-table-column>
      </el-table>

      <!--    分页组件-->
      <el-row justify="end" align="middle" style="margin-top: 20px;">
        <el-pagination
            v-model:current-page="pageInfo.currentPage"
            v-model:page-size="pageInfo.pageSize"
            v-model:total="pageInfo.totalItem"
            :page-sizes="[10, 20, 50, 100]"
            background
            layout="sizes, prev, pager, next,total"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
      </el-row>
    </div>
  </template>
  
  <script setup>
  import {ref, reactive, onMounted} from 'vue';
  import {ElMessage} from "element-plus";
  import {filterEmptyFields, resetReactive, getValueFromLabel, readResponse, createPageInfo } from "@/utils/index";
  import {getTaskList, deleteTask} from "@/api/task";

  // 单独的pageInfo对象
  const pageInfo = reactive(createPageInfo());
  //创建搜索的任务对象
  const taskQuery = reactive({
    queryType:'create',
    taskName:'',
    taskType:'',
    taskStatus:'',
    executionDate:'',
    executionTime:''
  });


  //任务类型下拉选择
  const taskTypeOption = [
    {
      label:'系统任务',
      value:'0'
    },
    {
      label: '用户任务',
      value:'1'
    }
  ];

  //任务状态下拉选择
  const taskStatusOption = [
    {
      label: '已激活',
      value:'active',
    },
    {
      label: '未激活',
      value:'inactive',
    }
  ]

  const taskList = ref([]);


  onMounted(() => {
    onSubmit();
  })
  //执行搜索
  const onSubmit = async () => {
    await handleSearch(taskQuery);
  }

  //执行重置
  const reset = async () => {
    resetReactive(taskQuery);
    pageInfo.currentPage = 1;
    pageInfo.pageSize = 10;
    taskQuery.queryType='create';
    await handleSearch(taskQuery);
  }
  //分页查询动作
  const handleCurrentChange = async (curPage) =>{
    pageInfo.currentPage = curPage;
    await handleSearch(taskQuery);
  }
  //调整分页大小
  const handleSizeChange = async (pageSize) =>{
    pageInfo.pageSize = pageSize;
    await handleSearch(taskQuery);
  }
  //发起请求
  const handleSearch = async (taskQuery) => {
    const body = {...filterEmptyFields(taskQuery), ...pageInfo}
    const response = await getTaskList(body);
    if (response.data.code === 200) {
      // console.log(response.data);
      ElMessage.success("查询成功");
      taskList.value = readResponse(response, pageInfo);
    } else {
      ElMessage.error(response.data.errorMessage);
    }
  };

  //删除请求
  const deleteMyTask = async (row) => {
    const response = await deleteTask(row.id);
    if (response.data.code === 200) {
      ElMessage.success("删除成功");
      await handleSearch(taskQuery);
    } else {
      ElMessage.error(response.data.errorMessage);
    }
  }

  // //编辑请求
  // const edit = async (row) => {
  //   console.log(row);
  // }
  //
  // //订阅请求
  // const bandTask = async (row) => {
  //   console.log(row);
  // }
  //
  // //查询订阅用户请求
  // const queryBandUser = async (row) => {
  // }

  </script>
  